import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css
window.Config = {}


import App from './App'
import router from './router'
import store from './store'

import i18n from './lang' // Internationalization
import './icons' // icon
import './errorLog' // error log
import './permission' // permission control
import './mock' // simulation data

import * as filters from './filters' // global filters
import moment from 'moment'
// 引入图片查看器
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
import format from 'vue-text-format'


Vue.use(format)

Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999
  }
})

Vue.directive('checkSubmit', {
  inserted(el) {
    el.addEventListener('focus', () => {
      el.children[1].style.display = 'none'
      el.children[0].style.display = 'block'
      el.children[0].querySelector('input').focus()
    })
    el.children[0].querySelector('input').addEventListener('blur', () => {
      el.children[0].style.display = 'none'
      el.children[1].style.display = 'block'
    })
  }
})

Vue.directive('focus', el => {
  el.querySelector('input').focus()
})


Vue.use(Element, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  template: '<App/>',
  components: {
    App
  }
})

Vue.filter('cutTime', value => {
  if (!value) {
    return ''
  }
  return moment(value).format('YYYY-MM-DD HH:mm:ss')
})
